#include "base/core/script.h"
#include "Script/SkillScriptFunc.h"
#include "Script/ScriptMgr.h"

using namespace luabridge;

bool RegistSkillScriptFunc(lua_State* state)
{
	// 此处主要用来包装SkillMgr中的函数
	// 注意不要与skill.lua中的函数有名字冲突
	getGlobalNamespace(state).beginNamespace("SkillMgr")
		.addCFunction("LuaSkillInfo", LuaSkillInfo)
		.endNamespace();
	return true;
}

namespace
{
/* lua 调用这个函数的方法
function Skill:NotifySkillInfo()
	local tbSkillInfo =
	{
		hurtValue = 1,
		defenseValue = 1,
	}
	Skill:LuaSkillInfo(tbSkillInfo);
end
*/
int LuaSkillInfo(lua_State* state)
{
	bool result = false;
	//int hurtValue = 0;
	//int defenseValue = 0;

	LuaScript* pScript = g_GetScriptMgr()->GetScript();
	luabridge::LuaRef refSkillInfo = luabridge::LuaRef::fromStack(state, lua_gettop(state));
	MMOLOG_PROCESS_ERROR(refSkillInfo.isTable());
	MMOLOG_PROCESS_ERROR(pScript);

	MMOLOG_PROCESS_ERROR(refSkillInfo["hurtValue"].isNumber());
	//hurtValue = refSkillInfo["hurtValue"].cast<int>();

	MMOLOG_PROCESS_ERROR(refSkillInfo["defenseValue"].isNumber());
	//defenseValue = refSkillInfo["defenseValue"].cast<int>();

	result = true;
Exit0:
	pScript->PushInt(result ? 1 : 0);
	return 1;
}
}